package fr.upmc.tps.mdoc.client;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import fr.upmc.tps.mdoc.entity.Contact;
import fr.upmc.tps.mdoc.sessions.GestionContactRemote;
import fr.upmc.tps.mdoc.tools.EJBUtils;

public class Main {
	public static void main(String[] args) {

		try {
			// Use of JNDI in order to identify and to communicate
			// with the remote beans
			Context context = new InitialContext();

			// here, we use the name of the bean i.e. mappedName and not the
			// class name
			GestionContactRemote beanRemote = (GestionContactRemote) context
					.lookup("ContactBean");
			System.out.println(beanRemote
					.coucouContact("Coucou: Mon Premier Client EJB3"));

			beanRemote = (GestionContactRemote) context.lookup("ContactBean");

			// add a contact
			Contact contact = EJBUtils.createContact("Boina", "ali",
					"ali.boina@gmail.com");
			beanRemote.addContact(contact.getFirstName(),
					contact.getLastName(), contact.getEmail());

			// affichage du nom du contact ajouté
			beanRemote.findContactNameById(contact.getContactId());

			System.out.println("Ajout contact : Mon 2eme Client EJB3");

		} catch (NamingException e) {
			e.printStackTrace();
		}

	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see java.lang.Object#Object()
	 */
	public Main() {
		super();
	}

}